package com.whu.MenuHub.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.whu.MenuHub.domain.ReceivingAddress;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

@Mapper
public interface ReceivingAddressDao extends BaseMapper<ReceivingAddress> {

    @Insert("INSERT INTO receivingaddress (userID,,recipientName,phoneNumber,address,isDefaultAddress) " +
            "VALUES (#{userID},#{recipientName},#{phoneNumber},{address},{isDefaultAddress})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id",
            keyColumn = "id", resultType = Integer.class, before = false)
    void insertAddress(ReceivingAddress address);

    @Select("select * from receivingaddress where userID=#{userID} and isDefaultAddress=1")
    ReceivingAddress getDefaultAddress(Integer userID);
}
